package com.qfedu.lc.app.controller;

import com.qfedu.lc.app.service.UserFeign;
import com.qfedu.lc.common.config.SystemConfig;
import com.qfedu.lc.common.param.UserAdd;
import com.qfedu.lc.common.param.UserLogin;
import com.qfedu.lc.common.vo.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;

/**
 * --- 年薪百万 ---
 * ---So easy---
 *
 * @author ZhiHuiJun
 * @motto 学习都是人上人
 * @desc 就是很帅很优秀
 * @CC 每天漂亮、幸福、快乐、自由
 */
@RequestMapping("/api/user")
@RestController
public class UserController {

    @Autowired
    private UserFeign userFeign;

    @ApiOperation("注册接口")
    @RequestMapping(value = "/register",method = RequestMethod.POST)
    public R register(@RequestBody UserAdd userAdd) {
        return userFeign.register(userAdd);
    }

    @ApiOperation("账号 密码登录接口")
    @RequestMapping(value = "/loginpass",method = RequestMethod.POST)
    public R login(@RequestBody UserLogin userLogin) {
        return userFeign.login(userLogin);
    }

    @ApiOperation("手机号 验证码登录接口")
    @RequestMapping(value = "/logincode",method = RequestMethod.POST)
    public R logincode(@RequestBody UserLogin userLogin) {
        return userFeign.logincode(userLogin);
    }

    @ApiOperation(value = "退出接口")
    @RequestMapping(value = "/logout" ,method = RequestMethod.GET)
    public R logout(HttpServletRequest request) {
        String token = request.getHeader(SystemConfig.HEADER_TOKEN);
        return userFeign.logout();
    }
}
